import time


class Auto(object):
    max_velocity = 120

    def __init__(self, tire_num, color, weight, velocity=0):
        self.tire_num = tire_num
        self.color = color
        self.weight = weight
        self.velocity = velocity

    def show_velocity(self):
        print('velocity = {}'.format(self.velocity))

    def accelerate(self):
        if self.velocity < self.max_velocity:
            self.velocity += 5
        self.show_velocity()

    def decelerate(self):
        if self.velocity > 0:
            self.velocity -= 5
        self.show_velocity()

    def stop(self):
        if self.velocity > 0:
            self.decelerate()
            self.stop()


class CarAuto(Auto):
    __accelerate = False
    __decelerate = False

    def __init__(self, tire_num, color, weight, velocity=0, air_condition='无', cd='无'):
        super(CarAuto, self).__init__(tire_num, color, weight, velocity)
        self.air_condition = air_condition
        self.cd = cd

    def is_accelerate(self, isac):
        if isac:
            self.__accelerate = True
            self.__decelerate = False
        else:
            self.__accelerate = False

    def is_decelerate(self, isde):
        if isde:
            self.__decelerate = True
            self.__accelerate = False
        else:
            self.__decelerate = False

    def keep_velocity(self):
        self.__accelerate = False
        self.__decelerate = False

    def accelerate(self):  # 加速直到max_velocity
        if self.velocity < self.max_velocity:
            self.is_accelerate(True)
            time.sleep(0.5)
            print('car auto accelerated')
            super(CarAuto, self).accelerate()
            self.accelerate()
        else:
            self.is_accelerate(False)

    def decelerate(self):  # 减速直到0
        if self.velocity > 0:
            self.is_decelerate(True)
            time.sleep(0.5)
            print('car auto decelerated')
            super(CarAuto, self).decelerate()
            self.decelerate()
        else:
            self.is_decelerate(False)

    def stop(self):
        self.decelerate()


auto = Auto(4, 'blue', 1000, 100)
auto.stop()
auto.accelerate()
auto.decelerate()

car_auto = CarAuto(8, 'red', 800, 90, '格力', 'Jay Chou')
car_auto.accelerate()
car_auto.decelerate()
